package com.zjpavt.client.artnet.effect;

import com.zjpavt.client.artnet.device.StripLight;

public class WaterWaveEffect implements IEffect {
    private transient  StripLight stripLight;
    private byte[] backGround;
    private byte[] runColor;
    private double variate;
    private double speed = 1;

    public WaterWaveEffect(StripLight stripLight, byte[] backGround, byte[] runColor) {
        this.stripLight = stripLight;
        this.backGround = backGround;
        this.runColor = runColor;
    }

    public WaterWaveEffect(StripLight stripLight, byte[] backGround, byte[] runColor,double speed) {
        this.stripLight = stripLight;
        this.backGround = backGround;
        this.runColor = runColor;
        this.speed = speed;
    }

    @Override
    public void show() {
        int channelNum = stripLight.getSingleLightChannelSize();
        int lightNum = stripLight.getLightNum();
        if (channelNum != backGround.length || channelNum != runColor.length) {
            return;
        }
        for (int index = 0; index < stripLight.getLightNum(); index++) {
            if (variate % 2 == index % 2) {
                stripLight.setLightColor(index, runColor);
            } else {
                stripLight.setLightColor(index, backGround);
            }
        }
        variate+=speed;
    }

    @Override
    public void setOwner(StripLight stripLight) {
        this.stripLight = stripLight;
    }
}
